/*     */ package com.java.diagnostics.visualizer.impl.templates;
/*     */ 
/*     */ import com.java.diagnostics.visualizer.impl.GCAndMemoryVisualizerImplPreferenceInitalizer;
/*     */ import com.java.diagnostics.visualizer.impl.preferences.GCAndMemoryVisualizerPreferenceInitializer;
/*     */ import com.java.diagnostics.visualizer.impl.preferences.SmartPreferences;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import org.eclipse.core.runtime.CoreException;
/*     */ import org.eclipse.core.runtime.preferences.IScopeContext;
/*     */ import org.eclipse.swt.graphics.Image;
/*     */ import org.osgi.service.prefs.BackingStoreException;
/*     */ 
/*     */ public abstract class Template
/*     */   implements Comparable
/*     */ {
/*     */   private static final String DOT = "\\.";
/*     */   protected static final String EPF_SUFFIX = ".epf";
/*     */   protected String name;
/*     */   protected String description;
/*     */   protected Image icon;
/*     */   protected String iconUrl;
/*     */ 
/*     */   public Template()
/*     */   {
/*     */   }
/*     */ 
/*     */   protected Template(String name)
/*     */   {
/*  58 */     this();
/*  59 */     this.name = name;
/*  60 */     this.description = "";
/*     */ 
/*  62 */     if ((name != null) && 
/*  63 */       (name.lastIndexOf(".epf") == name.length() - ".epf".length()))
/*  64 */       this.name = name.substring(0, name.length() - ".epf".length());
/*     */   }
/*     */ 
/*     */   public String getName()
/*     */   {
/*  69 */     return this.name;
/*     */   }
/*     */ 
/*     */   public void setName(String name) {
/*  73 */     this.name = name;
/*     */   }
/*     */ 
/*     */   public void importPreferences(IScopeContext scope) throws IOException, CoreException, BackingStoreException
/*     */   {
/*  78 */     SmartPreferences preferences = GCAndMemoryVisualizerImplPreferenceInitalizer.getInstance()
/*  79 */       .getPreferences(scope);
/*     */ 
/*  81 */     InputStream stream = getStream();
/*  82 */     if (stream != null) {
/*  83 */       preferences.importPreferences(stream);
/*  84 */       stream.close();
/*     */     }
/*     */   }
/*     */ 
/*     */   protected abstract InputStream getStream()
/*     */     throws FileNotFoundException;
/*     */ 
/*     */   public int compareTo(Object o)
/*     */   {
/*  94 */     if ((o instanceof Template)) {
/*  95 */       if (equals(o)) {
/*  96 */         return 0;
/*     */       }
/*  98 */       Template template = (Template)o;
/*     */ 
/* 100 */       if (((o instanceof ResourceTemplate)) && 
/* 101 */         ((this instanceof FileTemplate)))
/* 102 */         return -1;
/* 103 */       if (((o instanceof FileTemplate)) && 
/* 104 */         ((this instanceof ResourceTemplate))) {
/* 105 */         return 1;
/*     */       }
/* 107 */       int ret = this.name.compareTo(template.name);
/* 108 */       if (ret != 0) {
/* 109 */         return ret;
/*     */       }
/* 111 */       return this.description.compareTo(template.description);
/*     */     }
/*     */ 
/* 116 */     return -1;
/*     */   }
/*     */ 
/*     */   public String getDescription() {
/* 120 */     return this.description;
/*     */   }
/*     */ 
/*     */   public void setDescription(String description) {
/* 124 */     this.description = description;
/*     */   }
/*     */ 
/*     */   public void setIconUrl(String iconDescriptor) {
/* 128 */     this.iconUrl = iconDescriptor;
/*     */   }
/*     */ 
/*     */   public String getIconUrl() {
/* 132 */     return this.iconUrl;
/*     */   }
/*     */ 
/*     */   public String getDisplayDescription() {
/* 136 */     return getDescription();
/*     */   }
/*     */ 
/*     */   public String getDisplayName() {
/* 140 */     return getName();
/*     */   }
/*     */ }

